<?php

class Core_Model_Foundation_Collection_Poi extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('foundation/poi');
        $this->from('{t}foundation_poi', 'a')->field('a.*')
             ->where()->not()->isNull('a.industry_id');
    }

    public function joinIndustry(){
       return $this->innerJoin('{t}ritu_industry', 'c', 'a.industry_id', 'c.id')
                   ->field('c.name3', 'industry_name');
    }

    public function joinRoad(){
        return $this->innerJoin('{t}foundation_road', 'b', 'a.road_id', 'b.id')
                ->field('b.province_name')
                ->field('b.city_name')
                ->field('b.district_name')
                ->field('b.townstreet_name')
                ->field('b.road_name');
    }

    public function joinVisit(){
        return $this->innerJoin('{t}poi_visit', 'e', 'a.id', 'e.id')
                    ->field('e.click_count');
    }

    public function joinAccount(){
        return $this->innerJoin('{t}account_poi','f','a.id','f.poi_id')->field('f.account_id','account_id');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'poiid':
                return $this->eq('a.id', ':poiId:s')->addParameter('poiId', "$arg");
            case 'poi':
                return $this->like('a.id', ':poiId:s')->addParameter('poiId', "%$arg%");
            case 'poiids':
                return $this->contain('a.id', ':poiIds:s')->addParameter('poiIds', $arg);       
            case 'shopname':
                return $this->like('a.shop_name', ':shopName:s')->addParameter('shopName', '%' . $arg . '%');
            case 'industryname':
                return $this->like('c.name3', ':industryName:s')->addParameter('industryName', "%$arg%");
            case 'townstreetname':
                return $this->like('b.townstreet_name', ':townstreetName:s')->addParameter('townstreetName', "%$arg%");
            case 'roadname':
                return $this->like('b.road_name', ':roadName:s')->addParameter('roadName', "%$arg%");
            case 'districtname':
                return $this->like('b.district_name', ':districtName:s')->addParameter('districtName', "%$arg%");
            case 'ids':
                return $this->contain('a.id', ':ids:s')->addParameter('ids', $arg);
            case 'haspicture':
                return $this->where()->not()->isNull('a.photo');
            case 'nopicture':
                return $this->where()->isNull('a.photo');
            case 'roadid':
                return $this->like('a.road_id', ':roadId:s')->addParameter('roadId', $arg.'%');
            case 'industryid':
                return $this->like('a.industry_id', ':industryId:s')->addParameter('industryId', $arg.'%');
            case 'accoundid':
                return $this->eq('f.account_id',':accound_id:i')->addParameter('accound_id',$arg);
        }
        return $this;
    }

}